package com.zsck.zsgy.ui.main.fragment.simplecircle

import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.KeyboardUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.zsck.commonbase.widget.SearchView
import com.zsck.zsgy.R
import com.zsck.zsgy.base.BaseFragment
import com.zsck.zsgy.databinding.FragmentSimpleListBinding
import com.zsck.zsgy.databinding.FragmentSimpleSearchBinding
import com.zsck.zsgy.ui.main.fragment.simplecircle.adapter.SimpleActivityAdapter

class SimpleActivityFragment : BaseFragment<SimpleCircleViewModel, FragmentSimpleSearchBinding>() {


    companion object {
        fun newInstance() = SimpleActivityFragment()
    }

    private var activityAdapter = SimpleActivityAdapter()

    override fun initView(savedInstanceState: Bundle?) {
        binding.rcvActivity.isNestedScrollingEnabled = false
        binding.rcvActivity.layoutManager = LinearLayoutManager(mContext)
        binding.rcvActivity.adapter = activityAdapter
        activityAdapter.setOnItemClickListener(object : OnItemClickListener {
            override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {

            }
        })


        activityAdapter.setOnItemClickListener(object : OnItemClickListener {
            override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {

            }
        })


        binding.searchView.setOnClickListener(object : SearchView.onClickListener {
            override fun selectClick(textView: TextView?) {
//                val intent = Intent(activity, SelectCityActivity::class.java)
//                startActivityForResult(
//                    intent,
//                    com.zsck.zsgy.fragments.ActivityListFragment.REQUEST_CODE_LOCATION
//                )
            }

            override fun searchClick(editText: EditText?) {
                binding.searchView.focusable(true)
                editText?.let { KeyboardUtils.showSoftInput(it) }
            }

            override fun dosearchAction(editText: EditText) {
                binding.searchView.focusable(false)
                page = 1
                keyword = editText.text.toString()
                editText?.let { KeyboardUtils.hideSoftInput(it) }
                loadactiivty()
            }

            override fun doDelteAll(editText: EditText) {
                binding.searchView.focusable(false)
                page = 1
                keyword = editText.text.toString()
                loadactiivty()
            }
        })

    }

    override fun layoutId(): Int {
        return R.layout.fragment_simple_search

    }

    override fun initData() {
        loadactiivty()

    }

    private var page = 1
    private var keyword = ""

    private fun loadactiivty() {
        viewModel.simpleCircleActivity(page, keyword)
        viewModel.simpleCircleActivityModel.observe(this, {
            activityAdapter.setList(it?.rows)
        })

    }
}